package com.fh.shop.api.book.controller;

import com.fh.shop.api.book.biz.IBookService;
import com.fh.shop.api.book.param.BookQueryParam;
import com.fh.shop.api.book.po.Book;
import com.fh.shop.api.common.DataTableReponse;
import com.fh.shop.api.common.ServerResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/api/book")
@CrossOrigin
@RestController
public class BookController {

    @Resource(name = "bookService")
    private IBookService bookService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ServerResponse add(Book book) {
        return bookService.addBook(book);
    }

    @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
    public DataTableReponse findPageList(BookQueryParam bookQueryParam) {
        return bookService.findPageList(bookQueryParam);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ServerResponse deleteBook(Long id) {
        return bookService.deleteBook(id);
    }

    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    public ServerResponse deleteBatch(@RequestBody List<Long> idList) {
            return bookService.deleteBatch(idList);
    }

    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public ServerResponse find(Long id) {
        return bookService.findBook(id);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ServerResponse update(Book book) {
        return bookService.updateBook(book);
    }

    @RequestMapping(value = "/updateBook", method = RequestMethod.POST)
    public ServerResponse updateBook(@RequestBody Book book) {
        return bookService.updateBook(book);
    }


}
